package com.seeyon.apps.kkARPEvent.util;

import com.seeyon.ctp.common.exceptions.BusinessException;
import com.seeyon.ctp.util.JDBCAgent;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.util.List;
import java.util.Map;

/**
 * @description: 描述
 * @author: user
 * @copyright 公司版权所有
 * @version: V1.0
 * @date: 2024-04-02 13:28
 */
public class SqlUtil {

    private static final Log log = LogFactory.getLog(SqlUtil.class);

    /**
     * 通过SQL查询
     *
     * @param str
     * @param params
     * @return
     * @throws BusinessException
     */
    public static List<Map<String, Object>> doQuery(String str, Map<String, Object> params) throws BusinessException {
        JDBCAgent agent = new JDBCAgent(true, false);
        try {
            if (MapUtils.isEmpty(params)) {
                agent.execute(str);
            } else {
                agent.executeNamedSql(str, params);
            }
            return agent.resultSetToList();
        } catch (Exception e) {
            log.error("##客开: 数据查询失败!", e);
            throw new BusinessException(e);
        } finally {
            if (agent != null) {
                agent.close();
            }
        }
    }
}
